<html>
<head><meta charset="utf-8"><title>Destructing of &amp;mut self to reduce scoping · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Destructing.20of.20.26mut.20self.20to.20reduce.20scoping.html">Destructing of &amp;mut self to reduce scoping</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247523823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Destructing%20of%20%26mut%20self%20to%20reduce%20scoping/near/247523823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brandon Falk <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Destructing.20of.20.26mut.20self.20to.20reduce.20scoping.html#247523823">(Jul 28 2021 at 22:14)</a>:</h4>
<p>Is there any way to destructure something along the lines of <code>fn foo(&amp;mut self) { self.values.push(0) }</code> where you can destructure <code>self</code> in way that the compiler would know that not all of <code>self</code> needs to be borrowed, but only <code>self.values</code>?</p>
<p>I've tried doing <code>fn(Self { ref mut values, .. }: &amp;mut Self)</code> although the compiler doesn't know that the function only needs access to <code>values</code>, also it's considered an associated function which is a bit annoying</p>



<a name="247524125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Destructing%20of%20%26mut%20self%20to%20reduce%20scoping/near/247524125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brandon Falk <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Destructing.20of.20.26mut.20self.20to.20reduce.20scoping.html#247524125">(Jul 28 2021 at 22:17)</a>:</h4>
<p>Ideally this would be automated as it is done in closures in 2021 Rust, but I don't know how hard that would be</p>



<a name="247524682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Destructing%20of%20%26mut%20self%20to%20reduce%20scoping/near/247524682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Destructing.20of.20.26mut.20self.20to.20reduce.20scoping.html#247524682">(Jul 28 2021 at 22:23)</a>:</h4>
<p>Unfortunately, no</p>



<a name="247524750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Destructing%20of%20%26mut%20self%20to%20reduce%20scoping/near/247524750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Destructing.20of.20.26mut.20self.20to.20reduce.20scoping.html#247524750">(Jul 28 2021 at 22:24)</a>:</h4>
<p>See this blog post for a discussion of the topic: <a href="https://smallcultfollowing.com/babysteps/blog/2018/11/01/after-nll-interprocedural-conflicts/">https://smallcultfollowing.com/babysteps/blog/2018/11/01/after-nll-interprocedural-conflicts/</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>